<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<c:if test="${mcList==null}">
	<c:redirect url="/servlet/McManageServlet?fromPage=/Admin/Admin_Mclist.jsp"></c:redirect>
</c:if>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Shop 管理中心 - 商品列表 </title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="<c:url value="/Admin/styles/general.css" />" rel="stylesheet" type="text/css" />
	<link href="<c:url value="/Admin/styles/main.css" />" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<c:url value="/js/user.js" />"></script>
    <script language="javascript">
    <c:forEach var="mcTypeMap" items="${mcTypeList}">
    <c:forEach var="me" items="${mcTypeMap}">
        <c:set var="maxType" value="${me.key}" />
        <c:set var="minList" value="${me.value}"/>
    </c:forEach>
        var array_${maxType.nid}=new Array();
        <c:forEach var="minType" items="${minList}" varStatus="lStatus">
            array_${maxType.nid}[${lStatus.index}]="${minType.nid};${minType.sname}";
        </c:forEach>
    </c:forEach>
    function maxChange() {
        var maxtypeObj = document.getElementById("maxType");
        var mintypeObj = document.getElementById("minType");
        
        var maxtype_value = maxtypeObj.value;
        mintypeObj.options.length=0;
        if(maxtype_value!=""){
            mintypeObj.options.add(new Option("所有小类",""));
            document.forms['searchForm'].elements['minType'].disabled = '';
            var arrayObj = eval("array_" + maxtype_value);
            for(i=0;i<arrayObj.length;i++) {
                var tmp_array=arrayObj[i].split(";");
                mintypeObj.options.add(new Option(tmp_array[1],tmp_array[0]));
            }
        } else {
            document.forms['searchForm'].elements['minType'].disabled = 'disabled';
        }
    }
    
    function minChange() {
        maxChange();
        var mintypeObj = document.getElementById("minType");
        
        for(i=0;i<mintypeObj.options.length;i++) {
            if(mintypeObj.options[i].value=="${typeMin}") {
                mintypeObj.options[i].selected=true;
                break;
            }
        }
    }
    
    function pagingOnClick(num){
        if(num==1){
            searchForm.curPage.value=1;
        }
        if(num==2){
            searchForm.curPage.value=${curPage} - 1;
        }
        if(num==3){
            searchForm.curPage.value=${curPage} + 1;
        }
        if(num==4){
            searchForm.curPage.value=${pageCount};
        }
        searchForm.submit();
    }
	function confirm_redirect(msg, url) {
		  if (confirm(msg)) {
			location.href=url;
		  }
	}
    </script>
    <c:if test="${not empty param.msg}">
    	<script language="javascript">
			alert('${param.msg}');
		</script>
    </c:if>

  </head>
  
  <body>
    <h1>
	<span class="action-span"><a href="<c:url value="/Admin/Admin_Mcadd.jsp" />">添加新商品</a></span>
	<span><a href="#">Shop 管理中心</a>  - 商品列表 </span>
	</h1>
	<div class="form-div">
		<form id="searchForm" name="searchForm" method="get" action="<c:url value="/servlet/McManageServlet" />">
			所属大类：
			<select name="maxType" id="maxType" onChange="maxChange();" style="vertical-align:middle;width:75px;">
			<option value="">所有分类</option>
			<c:forEach var="mcTypeMap" items="${mcTypeList}">
			<c:forEach var="me" items="${mcTypeMap}">
			<c:set var="maxType" value="${me.key}" />
			<c:choose>
			<c:when test="${typeMax==maxType.nid}">
				<option value="${maxType.nid}" selected="selected">${maxType.sname}</option>
			</c:when>
			<c:otherwise>
				<option value="${maxType.nid}">${maxType.sname}</option>
			</c:otherwise>
			</c:choose>
			</c:forEach>
			</c:forEach>
			</select>
			所属小类：
			<select name="minType" id="minType" style="vertical-align:middle;width:75px;"></select>
			<input type="hidden" name="fromPage" value="/Admin/Admin_Mclist.jsp" />
			关键字：
			<input name="skey" type="text" id="keyword" value="${param.skey}" size="10" />
			<input type="submit" value=" 搜索 " class="button" />
			<input type="hidden" name="curPage" value="1" />
		</form>
		</div>
		<div class="list-div" id="listDiv">
		<!--用户列表部分-->
		<table cellpadding="0" cellspacing="1">
		  <tr>
		    <th>图片</th>
		    <th>名称</th>
		    <th>单价</th>
		    <th>是否缺货</th>
		    <th>添加时间</th>
		    <th>操作</th>
		  </tr>
		  <c:forEach var="mcBean" items="${mcList}">
		  <tr>
		    <td align="center"><a href="<c:url value='/servlet/McInfoServlet' />?mcNid=${mcBean.nid}&fromPage=/Admin/Admin_Mcitem.jsp"><img src="<c:url value="/mcimg/${mcBean.simg}"/>" class="cimg" alt="${mcBean.sname}" /></a></td>
		    <td align="center"><a href="<c:url value='/servlet/McInfoServlet' />?mcNid=${mcBean.nid}&fromPage=/Admin/Admin_Mcitem.jsp" title="">${mcBean.sname}</a></td>
		    <td align="center">${mcBean.nprice}</td>
		    <td align="center">${mcBean.smctag}</td>
		    <td align="center">${mcBean.dcdate}</td>
		    <td align="center">
		    	<a href="<c:url value='/servlet/McInfoServlet' />?mcNid=${mcBean.nid}&fromPage=/Admin/Admin_Mcitem.jsp" title="查看商品详细信息">
		    	<img src="<c:url value="/Admin/images/icon_view.gif"/>" border="0" height="16" width="16" />
		    	</a>
		    	<a href="<c:url value='/servlet/McInfoServlet' />?mcNid=${mcBean.nid}&fromPage=/Admin/Admin_Mcedit.jsp" title="编辑商品信息">
		    	<img src="<c:url value="/Admin/images/icon_edit.gif"/>" border="0" height="16" width="16" />
		    	</a>
		    	<a href="#" onClick="confirm_redirect('您确定要删除该商品吗？','<c:url value='/servlet/McManageServlet?fromPage=/Admin/Admin_Mclist.jsp'/>&nid=${mcBean.nid}');return false;" title="删除该商品">
		        <img src="<c:url value="/Admin/images/icon_drop.gif"/>" border="0" height="16" width="16" />
		        </a>
		    </td>
		  </tr>
		  </c:forEach>
		  <tr>
		      <td align="right" nowrap="true" colspan="7" height="22px">
		            <div id="turn-page">
		        总计  <span id="totalRecords">${recordSize}</span>
		        个记录分为 <span id="totalPages">${pageCount}</span>
		        页当前第 <span id="pageCurrent">${curPage}</span>
		        页 
		        <span id="page-link">
		        <c:choose>
				<c:when test="${curPage==1}">
				<span>首页</span>
				<span>上一页</span>
				</c:when>
				<c:otherwise>
				<a href="#" onClick="pagingOnClick(1);return false;" >首页</a>
				<a href="#" onClick="pagingOnClick(2);return false;" >上一页</a>
				</c:otherwise>
				</c:choose>
				<c:choose>
				<c:when test="${curPage==pageCount}">
				<span>下一页</span>
				<span>尾页</span>
				</c:when>
				<c:otherwise>
				<a href="#" onClick="pagingOnClick(3);return false;" >下一页</a>
				<a href="#" onClick="pagingOnClick(4);return false;" >尾 页</a>
				</c:otherwise>
				</c:choose>
		        </span></div></td>
		  </tr>
		</table>
		</div>
		<div id="footer">版权所有 &copy;</div>
		<script type="text/javascript">
			window.onload = function()
			{
			  minChange();
			}
		</script>
  </body>
</html>
